/*
 * @Date: 2020-07-25 22:20:19
 * @LastEditors: 杨光辉(GerhardYang)
 * @LastEditTime: 2021-08-24 09:49:37
 * @FilePath: \hubei-police-search\src\setVuexLayerGroup.js
 * @Description:
 */

import L from "leaflet";

let setVuexLayerGroup = (_self, map) => {
  _self.$store.state.map = map;
  // 底图切换图层组
  _self.$store.state.baseLayerGroup = new L.layerGroup()
    .addTo(map)
    .setZIndex(1);
  //矢量底图图层组
  _self.$store.state.veccvaLayerGroup = new L.layerGroup()
    .addTo(_self.$store.state.baseLayerGroup)
    .setZIndex(2);
  //卫星底图图层组
  _self.$store.state.imgciaLayerGroup = new L.layerGroup()
    .addTo(_self.$store.state.baseLayerGroup)
    .setZIndex(3);
  //卫星底图图层组
  _self.$store.state.MultiLayerGroup = new L.layerGroup()
    .addTo(map)
    .setZIndex(4);
  _self.$store.state.suspendedGroup = new L.featureGroup()
    .addTo(map)
    .setZIndex(5);
  //图层树所有专题图全局图层组
  _self.$store.state.treeThemeMapLayerGroup = new L.layerGroup()
    .addTo(map)
    .setZIndex(6);
  //图层树空间查询结果要素组
  _self.$store.state.treeQueryFeatureGroup = new L.featureGroup()
    .addTo(map)
    .setZIndex(8);
  //图层树空间查询绘制图层
  _self.$store.state.querydrawFeatureGroup = new L.featureGroup()
    .addTo(map)
    .setZIndex(9);

  // //图层树聚合图全局图层组
  // _self.$store.state.treeClusterFeatureGroup = new L.FeatureGroup()
  //     .addTo(map)
  //     .setZIndex(23);
  // //图层树统计标签全局图层组
  // _self.$store.state.treeLableFeatureGroup = new L.FeatureGroup()
  //     .addTo(map)
  //     .setZIndex(23);
  //图层树统计标签全局图层组
  _self.$store.state.searchResultFeatureGroup = new L.FeatureGroup()
    .addTo(map)
    .setZIndex(23);
  //百米桩号查询图层
  _self.$store.state.searchstakesFeatureGroup = new L.FeatureGroup()
    .addTo(map)
    .setZIndex(23);

  /* POI */
  // POI搜索要素组
  _self.$store.state.markersFeatureGroup = new L.featureGroup()
    .addTo(map)
    .setZIndex(25);
  //POI二次搜索图层组
  _self.$store.state.poiCircletFeatureGroup = new L.featureGroup()
    .addTo(map)
    .setZIndex(12);

  /* 绘制查询 */
  // POI搜索要素组
  _self.$store.state.drawMarkersFeatureGroup = new L.featureGroup()
    .addTo(map)
    .setZIndex(15);

  //POI二次搜索图层组
  _self.$store.state.drawedFeatureGroup = new L.featureGroup()
    .addTo(map)
    .setZIndex(16);

  //地图标绘图层组
  _self.$store.state.mapLableFeatureGroup = new L.layerGroup()
    .addTo(map)
    .setZIndex(17);

  //行政区划图层组
  _self.$store.state.citiesLayerGroup = new L.layerGroup()
    .addTo(map)
    .setZIndex(22);
  //车辆轨迹图层
  _self.$store.state.vehicleTrackGroup = new L.featureGroup()
    .addTo(map)
    .setZIndex(16);
  //车辆轨迹图层
  _self.$store.state.vehicleLocationGroup = new L.featureGroup()
    .addTo(map)
    .setZIndex(16);
  //标注图层
  _self.$store.state.markelabelGroup = new L.featureGroup()
    .addTo(map)
    .setZIndex(26);
  //日新图层

  //路径规划
  _self.$store.state.routeGroup = new L.featureGroup().addTo(map).setZIndex(27);

  /* ##################################################################### */
  // 默认添加矢量底图
  let SearchLayers = _self.$store.state.config.SearchLayers;
  if (SearchLayers) {
    SearchLayers.map((item) => {
      let layerUrl = window.getServiceUrl(
        item.url,
        window.servicesPorts.iserver
      );
      if (item.typeText == "矢量地图") {
        L.supermap
          .tiledMapLayer(layerUrl, {
            noWrap: true,
            maxZoom: 21,
            prjCoordSys: { epsgCode: 3857 },
            bounds: [
              [24.62, 108.783],
              [30.13, 114.25],
            ],
          })
          .addTo(_self.$store.state.veccvaLayerGroup)
          .setZIndex(2);
      }
      if (item.typeText == "矢量标签") {
        L.supermap
          .tiledMapLayer(layerUrl, {
            noWrap: true,
            maxZoom: 21,
            prjCoordSys: { epsgCode: 3857 },
            bounds: [
              [24.62, 108.783],
              [30.13, 114.25],
            ],
          })
          .addTo(_self.$store.state.veccvaLayerGroup)
          .setZIndex(2);
      }
    });
  }

  //leaflet-pm绘制工具对象
  let Icon = L.icon({
    iconUrl: `./img/icons/0_r.png`,
  });
  let drawer = {
    MarkerDrawer: new L.Draw.Marker(map, {
      icon: Icon,
    }),
    PolylineDrawer: new L.Draw.Polyline(map),
    CircleDrawer: new L.Draw.Circle(map),
    PolygonDrawer: new L.Draw.Polygon(map),
    RectangleDrawer: new L.Draw.Rectangle(map),
    CircleMarkerDrawer: new L.Draw.CircleMarker(map),
  };
  _self.$store.state.drawer = drawer;
};

export default setVuexLayerGroup;
